﻿/*-------------------------------------------------
    公用JS
    开发人：tss
    开发时间：2009-08-20
    修改人： 
---------------------------------------------------*/
/**
 * 系统初始化变量
 */
var initVar = {
		
	basePath : null,	
	desktopUrl : '/frame/frame!desktop.action'
};


/**************************  鼠标移动js 效果 start ************/

window.onload = setTbStyle;

/**
 * 鼠标移动颜色变量
 */
var colorVar = {
		
	overColor : '#eff6fc',    //鼠标移上颜色
	leaveColor : '#ffffff',   //鼠标离开颜色
    clickColor : '#e5eff9'    //鼠标点击颜色
	
};


/**
 * 设置表格鼠标移动点击事件颜色的动态改变
 * @return
 */
function setTbStyle(){

	var collsTr = document.getElementsByTagName("tr");
	for(var i = 0; i < collsTr.length; i++){
		var oTr = collsTr[i];
		if(oTr.id == "tb_tr"){
	
			oTr.style.cursor = 'hand';
			oTr.onmouseover = function(){ setStyle(this,colorVar.overColor);};
			oTr.onmouseleave = function(){
				setStyle(this,colorVar.leaveColor);							
			};
			
			if(oTr.cells(0).firstChild.type == 'checkbox'){
				oTr.onclick = function(){
					
					var oInput = this.cells(0).firstChild;
					if(oInput.type == 'checkbox'){  //点击是多选框
						
						oInput.checked = !oInput.checked;
						setParentChk();   //设置父多选框是否选中
						
						oInput.onclick = function(){
							this.checked = !this.checked;							
						}
					}
					
					if(this.style.backgroundColor == colorVar.leaveColor){
						setStyle(this,colorVar.clickColor);
					}else{
						setStyle(this,colorVar.leaveColor);				
					}				
			  };
			}

					
	  }	
	}	
}

/**
 * 设置父多选框是否选中
 * @return
 */
function setParentChk(){
	
	var collChk = document.getElementsByName("chkIds");
	var flag = true;
	for(var i = 0; i < collChk.length; i++){
		
		var oChk = collChk[i];
		if(!oChk.checked){
	       flag = false;
	       break;
	    }	
	}	
	var oChkAll = document.getElementById("chkAll");
	if(oChkAll){
		oChkAll.checked = flag;
	}
	
}


/**
 * 设置颜色
 * @param ob
 * @param color
 * @return
 */
function setStyle(ob,color){
	
	ob.style.backgroundColor = color;
	var oRadio = ob.cells(0).firstChild;
	if(oRadio.type == 'checkbox' &&  oRadio.checked){
		ob.style.backgroundColor = colorVar.clickColor;
	}					
	
}

/**
 * /全选或反选
 * @param ob
 * @param chkIds
 * @return
 */
function checkAll(ob,chkIds){
	
	var chkObjs = document.getElementsByName(chkIds);
	for(var i = 0; i < chkObjs.length; i++){
		chkObjs[i].checked = ob.checked;
		if(ob.checked){
			chkObjs[i].parentNode.parentNode.style.backgroundColor = colorVar.clickColor;
		}else{
			chkObjs[i].parentNode.parentNode.style.backgroundColor = colorVar.leaveColor;
		}
    }
 
 }

/**************************  鼠标移动js 效果 end ************/


/**
 * 弹出模式窗体
 * @param url 链接名称
 * @param ids 隐藏 Ids
 * @param userNames 文本
 * @param params  参数
 * @return
 */
function openWin(url){
	
    url = initVar.basePath+url;
    window.open(url,"_blank","");
}

function openDialogWin(url,ids,userNames,params){
	
	var oIds = document.getElementById(ids);
	var oUserNames= document.getElementById(userNames);
	if(typeof(params) == 'undefined'){
		params = oIds.value;
	}
	url = initVar.basePath+url;
	var returnValue = window.showModalDialog(url,params,"dialogWidth=500px;dialogHeight=600px;status=no;help=no;scrollbars=no");
	if(returnValue != undefined){
		var strs = returnValue.split(";");
		oIds.value = strs[0];
		oUserNames.value = strs[1];
	}	
}


//执行提交
function doSubmit(form,url,act){
	
	if(typeof(act) != 'undefined'){
		if(act == 'parent'){
			parent.form.action = initVar.basePath+url;
		}
	}else{
		form.action = initVar.basePath+url;
	}
	form.submit();
}


//执行打开窗口
function doOpenWin(url){
	
	url = initVar.basePath+url;
	window.open(url, "");
}

//执行链接跳转
function doLink(url){
	
	window.location = initVar.basePath+url;
}

//获得checkbox 选择的 ids
function getSelectIds(chkIds){
	
    var ids = "";
	var chkObjs = document.getElementsByName(chkIds);
	for(var i = 0; i < chkObjs.length; i++){
		if(chkObjs[i].checked){
             ids += chkObjs[i].value+",";
        }
    }
	if(ids != ""){
		ids = ids.substring(0, ids.length-1);
	}
	return ids;
	
}

//获得checkbox 选择的 第一项Id
function getSelectFirstId(chkIds){
	
	var ids = getSelectIds(chkIds);
	var id = null;
	if(ids != null && ids != ""){
		id = ids.split(",")[0];
	}
	return id;
}

//删除
function commonRemove(form,url,chkIds){
	   	 
    var ids = getSelectIds(chkIds);

    if(ids.length == 0){
         alert("请选择你要删除的项");
         return;
    }else if(!confirm("你确认要删除吗?")){
    	return;
    }
    form.action = initVar.basePath+url + "?ids="+ids;
    form.submit();   
	
}


//事件监听
function execEvent(obj,tag,typeStr){
	
	var elments = document.getElementsByTagName(tag);
	for ( var i = 0; i < elments.length; i++) {
		var element = elments[i];
		with(element){
			if(tagName && id){
				switch(tagName){
				
				case 'A':
					
					if (href) {
						if (obj[id] != null) {
							var str = href.substring(href.indexOf(":")+1,href.length);
							str = str.split("|");
							href =  "javascript:"+obj.id+"."+id+"("+str+")";
						}
					};
					break;
					
				default:
					if (typeStr && type == typeStr) {
						
						if (obj[id] != null) {
							
							onclick = function(){
								var paramValue = getAttribute("param");
								if(paramValue != null){
									
									if(paramValue.indexOf("|") != -1){
										paramValue = paramValue.toString().split("|");
									}
									obj[id](paramValue);
								}else{
									obj[id]();
								}
							}
						}
					};
				}
			}
		}
	}
}


/**************  google Analytics  start ****************************/

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16424138-2']);
_gaq.push(['_trackPageview']);
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/**************  google Analytics  end ****************************/

/********************  baidu 网站统计 start *******************/

var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F6cdfcf41574539505b8ca234ed53a652' type='text/javascript'%3E%3C/script%3E"));

/********************  baidu 网站统计 end *******************/